﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CourseUtils;
using System.IO;

namespace CRUD
{
    class Program
    {
        #region static variables
        static String Path = @"Table";
        static String StaffFileName = "Staff.txt";
        static String BranchFileName = "Branch.txt";
        #endregion

        static void Main(string[] args)
        {
            // create the tools instance
            Tools tools = new Tools();

            #region Create Directory for Data Base
            if (!(tools.IsDirectoryExist(Path)))
            {
                tools.CreateDirectory(Path);
            }
            #endregion

            #region Create File for Data Base "StaffFileName" Table
            if (!(tools.IsTableExist(Path + "\\" + StaffFileName)))
            {
                Console.WriteLine("File .\\{0} does not exist!", Path + "\\" + StaffFileName);
                tools.CreateDataBaseFile(Path + "\\" + StaffFileName);
            }
            else 
                Console.WriteLine("File .\\{0} exists!", Path + "\\" + StaffFileName);
            #endregion

            #region Create File for Data Base "BranchFileName" Table
            if (!(tools.IsTableExist(Path + "\\" + BranchFileName)))
            {
                Console.WriteLine("File .\\{0} does not exist!", Path + "\\" + BranchFileName);
                tools.CreateDataBaseFile(Path + "\\" + BranchFileName);
                Console.WriteLine("And now file .\\{0} exists!", Path + "\\" + BranchFileName);

            }
            else
                Console.WriteLine("File .\\{0} exists!", Path + "\\" + BranchFileName);
            #endregion

            #region Create one record in Staff table (there is a bug of datetime field yet)
            Staff nextRecord = new Staff();
            nextRecord = tools.FeedStaffRecord(nextRecord);
            String PrepaiedRecord = nextRecord.StaffNo + ";" + nextRecord.FName + ";" + nextRecord.LName + ";" + nextRecord.Position + ";" + 
                nextRecord.Sex + ";" + nextRecord.DateOfBirth + ";" + nextRecord.Salary + ";" + nextRecord.BranchNo + ";";
            File.WriteAllText(Path + "\\" + StaffFileName, PrepaiedRecord);
            #endregion

        }
    }
}
